package com.kingbook.core.base;

import com.kingbook.core.result.JSONPageResult;
import com.kingbook.core.result.JSONResult;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author Bucky
 * @Date 2019-11-16 00:36:32
 * @Version 1.0
 */
public class SupportService extends BaseService {

    public JSONResult save(Map<String, Object> param) {
        return insert("insert", param);
    }

    public JSONResult remove(int id, int mid) {
        return delete("delete", putMap(id, mid));
    }

    public JSONResult modify(Map<String, Object> param) {
        return update("update", param);
    }

    /**
     * 根据主键返回单条记录
     */
    public Map<String, Object> findMap(int id, int mid) {
        return findMap("query", putMap(id, mid));
    }

    public JSONResult find(int id, int mid) {
        return find("query", putMap(id, mid));
    }

    public <T> T find(int id, int mid, Class<T> clazz) {
        return findObject("query", putMap(id, mid), clazz);
    }


    /**
     * 根据条件返回多条记录
     */
    public JSONResult query(Map<String, ?> param) {
        return query("query", param);
    }

    public Map<String, Object>[] queryMap(Map<String, Object> param) {
        return queryMap("query", param);
    }

    public <T> List<T> queryList(Map<String, ?> param, Class<T> clazz) {
        return queryList("query", param, clazz);
    }

    /**
     * 根据条件分页查询
     */
    public JSONPageResult queryForPages(Map<String, ?> param) {
        return queryForPages("query", "getRows", param);
    }

    public JSONPageResult queryForPages(Map<String, ?> param, Class clazz) {
        return queryForPages("query", "getRows", param, clazz);
    }


    protected Map<String, Object> putMap(int id, int mid) {
        Map<String, Object> param = new HashMap<>(2);
        param.put("id", id);
        param.put("mid", mid);
        return param;
    }

}
